import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  ManyToOne,
  JoinColumn,
  Index,
} from 'typeorm';
import { User } from '../../auth/entities/user.entity';
import { Work } from './work.entity';

/**
 * 点赞记录实体
 */
@Entity('likes')
@Index(['userId', 'workId'], { unique: true }) // 联合唯一索引，防止重复点赞
export class Like {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ comment: '用户ID' })
  userId: number;

  @Column({ comment: '作品ID' })
  workId: number;

  @ManyToOne(() => User, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'userId' })
  user: User;

  @ManyToOne(() => Work, { onDelete: 'CASCADE' })
  @JoinColumn({ name: 'workId' })
  work: Work;

  @CreateDateColumn({ type: 'timestamp', comment: '点赞时间' })
  createdAt: Date;
}
